package com.niiwoo.civet.mobile.lanmao.handler;

import com.alibaba.fastjson.JSONObject;
import com.niiwoo.tripod.lanmao.enums.LanMaoGatewayServiceNameEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by zhangwanli on 2017/11/9.
 */
@Component
public class UserPreTransactionNotifyHandler implements LanMaoNotifyHandler {
	private static final Logger logger = LoggerFactory.getLogger(UserPreTransactionNotifyHandler.class);

	@Autowired
	private List<LanMaoBizNotifyHandler> handlers;

	@Override
	public boolean supports(String serviceName) {
		return LanMaoGatewayServiceNameEnum.USER_PRE_TRANSACTION.name().equals(serviceName);
	}

	@Override
	public HandleResult handle(JSONObject json) {
		HandleResult handleResult = null;
		for (LanMaoBizNotifyHandler handler : handlers) {
			if (handler.supports(json.getString("bizType"))) {
				logger.info("found LanMaoBizNotifyHandler: {} for {}", handler.getClass().getName(), json.getString("bizType"));
				return handler.handle(json);
			}
		}
		return null;
	}

}
